package cn.kgc.springmvc02.controller;

import cn.kgc.springmvc02.entity.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: mosin
 * @version: v1.0  2022/12/12
 * localhost:8080/user/add  ->add()
 * localhost:8080/user/delete  ->delete()
 *
 * @RestController  = @Controller +  @ResponseBody
 */
//@Controller
@RequestMapping("user")
//@ResponseBody
@RestController
public class UserController {

    //@RequestMapping("add")
    //public String add(){
    //    System.out.println("add请求被接收");
    //    return "index"; // 转发  视图名   ->视图解析器   -> /index.jsp
    //}
    //
    //@RequestMapping("delete")
    //public String delete(Integer id){
    //    System.out.println("delete请求被接收");
    //    return "index";
    //}

    @RequestMapping("u1")
    public User  getById(Integer id){
        User user = new User();
        user.setId(id);
        user.setUsername("tom");
        user.setAge(20);
        return user;
    }

    @RequestMapping("u2")
    //@ResponseBody
    public List<User> selectAll(){
        ArrayList<User> users = new ArrayList<>();
        User user = new User();
        user.setAge(20);
        user.setUsername("tom");
        users.add(user);
        users.add(user);
        users.add(user);
        return users;
    }



}
